package adv9;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class MyServer2 {
	public static void main(String[] args) {
		try {
			ServerSocket st = new ServerSocket(6666);
			System.out.println("服务启动了");
			while (true) {
				try {
					Socket s = st.accept();
					System.out.println(s + "链接了。。。");
					InputStream in = s.getInputStream();
					OutputStream out = s.getOutputStream();
					// System.out.println(in.getClass().getName());
					// System.out.println(out.getClass().getName());
					PrintWriter pw = new PrintWriter(out, true);
					BufferedReader br = new BufferedReader(
							new InputStreamReader(in));
					String str = br.readLine();
					System.out.println("客户端" + s.getInetAddress() + "说了" + str);
					pw.println("Laoliu say：" + str);
					s.close();
					System.out.println(s + "关闭了");
				} catch (Exception e) {
					System.out.println("有异常！");
				}
			}
		} catch (IOException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}

	}
}
